package com.hxxy.wyp.petsLover.common.rest.base.fronted;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxxy.wyp.petsLover.RestBase;
import com.hxxy.wyp.petsLover.common.entities.Good;
import com.hxxy.wyp.petsLover.common.entities.vo.req.SearchObj;
import com.hxxy.wyp.petsLover.common.services.base.backend.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName GoodFrontRest
 * @Description TODO
 * @Author wyp
 * @Date 2023/2/18 16:03
 * @Version 1.0
 */
@RestController
@ResponseBody
@RequestMapping("/goodFront")
public class GoodFrontRest extends RestBase {


    @Autowired
    private GoodService goodService;

    /**
     * 分页查询所有商品 带条件
     *
     * @param searchObj
     * @return
     */
    @RequestMapping("/all")
    public Object pageAll(@RequestBody SearchObj searchObj) {

        Page page = goodService.pageSearch(searchObj);
        return ajaxSuccess(page, "200", "查询成功！");
    }


    /**
     * 查询商品详情
     *
     * @param id
     * @return
     */
    @RequestMapping("/selectGoodInfo")
    public Object selectGoodInfo(@RequestParam("id") String id) {

        Good good = goodService.getById(id);
        List<String> picList = Arrays.stream(good.getPic().split(",")).collect(Collectors.toList());
        good.setPicList(picList);
        return ajaxSuccess(good, "200", "查询成功！");
    }


}
